package com.fanqiechaodan.proxy.jdkproxy.utils;

import com.fanqiechaodan.proxy.jdkproxy.service.UserService;
import com.fanqiechaodan.proxy.jdkproxy.service.impl.UserServiceImpl;

import java.lang.reflect.Proxy;

/**
 * @author fanqiechaodan
 * @Classname ProxyUtil
 * @Description
 */
public class ProxyUtil {

    public static UserService createProxy(UserServiceImpl userService){
        return (UserService) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(), new Class[]{UserService.class}, (proxy, method, args) -> {
            long start = System.currentTimeMillis();
            Object res = method.invoke(userService, args);
            System.out.println(method.getName()+"执行完成;耗时:"+(System.currentTimeMillis()-start)+"-----------");
            return res;
        });
    }
}
